﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.mediator;
using SharpSqlAnalyzer.pp.mediator.type;
using SharpSqlAnalyzer.pp.stmtformatter;

namespace SharpSqlAnalyzer.pp.processor.type.comm
{
	// Token: 0x02000253 RID: 595
	public class CombineWhitespaceAndClearReturnProcessor : AbstractProcessor
	{
		// Token: 0x0600132E RID: 4910 RVA: 0x0031D45C File Offset: 0x0031B65C
		public override void beforeProcess(TParseTreeNode node)
		{
			if (node.startToken == null || node.endToken == null)
			{
				return;
			}
			TSourceTokenList container = node.startToken.container;
			int num = node.startToken.posinlist;
			while (num < node.endToken.posinlist + 1 && num < container.size())
			{
				TSourceToken tsourceToken = container.get(num);
				if (!FormatterFactory.isNotNeedFormat(tsourceToken))
				{
					if (tsourceToken.tokentype == ETokenType.ttwhitespace)
					{
						tsourceToken.astext = " ";
					}
					else if (tsourceToken.tokentype == ETokenType.ttreturn && tsourceToken.posinlist > 0)
					{
						MediatorFactory.getMediator<SourceTokenTextTempMediator>(typeof(SourceTokenTextTempMediator), this.Option.sessionId).set(new int?(tsourceToken.posinlist), tsourceToken.astext);
						if (tsourceToken.container.get(tsourceToken.posinlist - 1).tokentype == ETokenType.ttwhitespace)
						{
							tsourceToken.astext = "";
						}
						else if (tsourceToken.posinlist < tsourceToken.container.size() - 1)
						{
							if (tsourceToken.container.get(tsourceToken.posinlist + 1).tokentype == ETokenType.ttwhitespace)
							{
								tsourceToken.astext = "";
							}
							else
							{
								tsourceToken.astext = " ";
							}
						}
						else
						{
							tsourceToken.astext = " ";
						}
						tsourceToken.tokentype = ETokenType.ttwhitespace;
					}
				}
				num++;
			}
		}
	}
}
